/**
 * Classe de gestion de l'accueil de Biodev
* @author I.T. Works.
* @date 20/12/2011
* @version 1.0
*/
package org.itworks.biodev.gui.panels;

import java.awt.event.*;
import java.util.*;

import javax.swing.*;
import org.itworks.biodev.gui.*;
import org.itworks.helpers.*;

public class HomePanelView extends JPanel implements Observer {

	private static final long serialVersionUID = 8162683878077275368L;
	private static HomePanelView homePanel = null;
	
	private MainWindowView parent = null;
	private JLabel biodevLogoLabel;
	private JButton viewCustomersButton;
    private JButton viewGiftsButton;
    private JButton viewMeetingsButton;
    private JButton viewParametersButton;
    private JButton viewProductsButton;
    private JButton viewSalariesButton;
    private JButton viewSalesButton;
    private JButton viewOrdersSupplierButton;
	
	private HomePanelView(MainWindowView parent) {
		
		this.parent = parent;
		
		initComponents();
		initHandlers();

	}
	
	/** Gestion du comportement des boutons*/
	private void initHandlers() {
		viewMeetingsButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectMeetingsTab();
				
			}
			
		});
		
		viewSalesButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectSalesTab();
			}
			
		});
		
		viewSalariesButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectSalariesTab();
			}
			
		});
		
		viewProductsButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectProductsTab();
			}
			
		});
		
		viewGiftsButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectGiftsTab();
			}
			
		});
		
		viewCustomersButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectCustomersTab();
			}
			
		});
		
		viewOrdersSupplierButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectOrdersSupplierTab();
			}
			
		});
		
		viewParametersButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent actionEvent) {
				// TODO Auto-generated method stub
				parent.selectParametersTab();
			}
			
		});
	}
	
	/**Agencement des onglets et boutons */
	private void initComponents() {
		ClassLoader cl = this.getClass().getClassLoader();
		biodevLogoLabel = new JLabel();
		biodevLogoLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        biodevLogoLabel.setIcon(new ImageIcon(cl.getResource("resources/images/biodev.png")));
        biodevLogoLabel.setHorizontalTextPosition(SwingConstants.CENTER);
        
        viewMeetingsButton = new JButton();
        viewSalesButton = new JButton();
        viewSalariesButton = new JButton();
        viewProductsButton = new JButton();
        viewGiftsButton = new JButton();
        viewCustomersButton = new JButton();
        viewParametersButton = new JButton();
        viewOrdersSupplierButton = new JButton();
        
        viewMeetingsButton.setText("Reunions");
        viewMeetingsButton.setIcon(new ImageIcon(cl.getResource("resources/images/meeting.png")));

        viewSalesButton.setText("Ventes");
        viewSalesButton.setIcon(new ImageIcon(cl.getResource("resources/images/sales.png")));

        viewSalariesButton.setText("Salaires");
        viewSalariesButton.setIcon(new ImageIcon(cl.getResource("resources/images/salary.png")));

        viewProductsButton.setText("Produits");
        viewProductsButton.setIcon(new ImageIcon(cl.getResource("resources/images/products.png")));

        viewGiftsButton.setText("Cadeaux & Avantages");
        viewGiftsButton.setIcon(new ImageIcon(cl.getResource("resources/images/gifts.png")));

        viewCustomersButton.setText("Clients");
        viewCustomersButton.setIcon(new ImageIcon(cl.getResource("resources/images/customers.png")));

        viewParametersButton.setText("Parametres");
        viewParametersButton.setIcon(new ImageIcon(cl.getResource("resources/images/configuration.png")));
        
        viewOrdersSupplierButton.setText("Commandes Fournisseur");
        viewOrdersSupplierButton.setIcon(new ImageIcon(cl.getResource("resources/images/order.png")));
        
        GroupLayout homePanelLayout = new GroupLayout(this);
        setLayout(homePanelLayout);
        homePanelLayout.setHorizontalGroup(
                homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(homePanelLayout.createSequentialGroup()
                    .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(homePanelLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(biodevLogoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 1080, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, homePanelLayout.createSequentialGroup()
                            .addGap(435, 435, 435)
                            .addComponent(viewOrdersSupplierButton, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                            .addGap(191, 191, 191)
                            .addComponent(viewParametersButton, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap())
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, homePanelLayout.createSequentialGroup()
                    .addContainerGap(315, Short.MAX_VALUE)
                    .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(viewGiftsButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(viewSalariesButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(viewMeetingsButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(homePanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(viewSalesButton, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, homePanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(viewProductsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, homePanelLayout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(viewCustomersButton, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(299, 299, 299))
            );
            homePanelLayout.setVerticalGroup(
                homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(homePanelLayout.createSequentialGroup()
                    .addComponent(biodevLogoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(viewMeetingsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(viewSalesButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(viewSalariesButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(viewProductsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(viewGiftsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(viewCustomersButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(homePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(homePanelLayout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
                            .addComponent(viewParametersButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(homePanelLayout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(viewOrdersSupplierButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())))
            );
	}
	
	/**Si la fenetre d'accueil n'est pas affichee on l'affiche*/
	public static HomePanelView getInstance(MainWindowView parent) {
		if(homePanel == null) {
			homePanel = new HomePanelView(parent);
		}
		return homePanel;
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		
		
	}
}
